package sys
{
	import flash.utils.getQualifiedClassName;
	
	import WInterface.IEvent;
	
	import utils.UIDUtil;

	/**
	 *对象基类 
	 * @author 张进辉
	 * 
	 */	
	public class EventBase implements IEvent
	{
		/**对象id*/
		public var id:String;
		
		
		/**事件管理*/
		private var _coreEvent:CoreEvent = Fcade.instance.coreEvent;
		
		/**唯一标识符*/
		private var _uid:String;
		
		/**当前对象拥有的全部事件类型*/
		private var _events:Vector.<String> = new Vector.<String>();
		/**当前事件功能是否可用*/
		private var _eventEnabled:Boolean;
		 
		public function EventBase()
		{
			id = _uid = UIDUtil.createUID();
		}
		
		/**获取类名*/
		public function get className():String
		{
			return getQualifiedClassName(this);
		}
		
		public function initialize():void
		{
			eventEnabled = true;
		}
		
		public function get uid():String
		{
			return _uid;
		}
		
		public function set eventEnabled(value:Boolean):void
		{
			if(_eventEnabled == value) return;
			if(value)
				_coreEvent.addEventItem(this);
			else
				_coreEvent.delEventItem(this);
		}
		
		public function get eventEnabled():Boolean
		{
			return _eventEnabled;
		}
		
		public function hasEvent(type:String):Boolean
		{
			for each (var i:String in _events) 
			{
				if(i == type)
					return true;
			}
			return false;
		}
		
		public function addEvent(type:String):void
		{
			if(hasEvent(type)) return;
			
			_events.push(type);
		}
		
		public function delEvent(type:String):void
		{
			for (var i:int = 0; i < _events.length; i++) 
			{
				var eventType:String = _events[i];
				if(eventType == type)
				{
					_events.splice(i,1);
					return;
				}
			} 
		}
		
		public function disEvent(type:String,data:Object=null):void
		{
			_coreEvent.tickEvent(type,data);
		}
		
		public function eventCallback(type:String,data:Object=null):void
		{
			
		}
		
		/**系统是否处于调试状态*/
		public function get debug():Boolean
		{
			return _coreEvent.debug;
		}
		
	}
}